package tgc.edu.yzy.service;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import tgc.edu.yzy.custom.CommonService;
import tgc.edu.yzy.entity.Student;
import tgc.edu.yzy.repository.StudentRepository;
@Service
public class StudentService extends CommonService<Student, Integer>{
	@Autowired
	private StudentRepository studentdao;
	
	/***
	 * 学生登陆
	 * @param username
	 * @param password
	 * @return
	 */
	public Student findBySnAndPassword(String username, String password) {
		return studentdao.findBySnAndPassword(username,password);
	}

	public List<Student> findByGradeId(Integer id) {
		return studentdao.findByGradeId(id);
	}

	@Transactional
	public void updatepassword(String password, Integer id) {
		studentdao.updatePassword(password,id);
		
	}

	public List<Student> findByBjId(Integer id) {
		return studentdao.findByBjId(id);
	}

	public Page<Student> findByBjId(Integer bjid, Pageable pageable) {
		return studentdao.findByBjId(bjid,pageable);
	}

	public Student findById1(Integer id) {
		Optional<Student> op = studentdao.findById(id);
		if(op.isPresent()) {
			return op.get();
		}
		return null;
	}
}
